<template>
    <div class="usercenter">
        <ul class="list-item">
            <li>
                <input type="text" v-model="user.currentPw" placeholder="当前密码"/>
            </li>
            <li style="margin-top:0">
                <input type="text" v-model="user.newPw" placeholder="新密码"/>
            </li>
            <li style="margin-top:0">
                <input type="text" v-model="user.confirmPw" placeholder="确认密码"/>
            </li>
        </ul>
        <div class="single-bottom-btn yellow" style="margin-top: 30px;" @click="edit">
            保存
        </div>
    </div>
</template>

<script>
  import {editPassword} from '_common/services/user'
  import wxLogin from '_common/wxLogin.js'
  export default {
    name: 'editPassword',
    data() {
      return {
        user: {
          currentPw: '',
          newPw: '',
          confirmPw: ''
        }
      }
    },
    computed: {},
    methods: {
      edit () {
        if (!this.user.currentPw || !this.user.newPw || !this.user.confirmPw) {
          this.$alertTip('请填写完整信息')
          return false
        }
        if (this.user.newPw !== this.user.confirmPw) {
          this.$alertTip('两次输入的新密码不一致！')
          return false
        }
        editPassword({
          oldPassword: this.user.currentPw,
          newPassword: this.user.newPw
        }).then(res => {
          if (res && res.code === 0) {
            this.$alertTip('修改成功')
          }
          else {
            this.$alertTip(res.msg || '修改失败，请稍后再试')
          }
        }, reject => {
          this.$alertTip('修改失败，请稍后再试')
        })
      }
    },
    async beforeMount() {
      await wxLogin(this.getData)
    },
    components: {}
  }
</script>
<style lang="less" scoped>
    @import "../../css/common";
    @import "../../css/commonlayout";

    .usercenter {
        font-size: 28px;
        .sendcode {
            color: @color_orange;
            width: 150px;
        }
    }

</style>